package controller;

import helper.AbstractAction;

import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;

import view.DatumAuswaehlenDialog;
import view.UeberweisungDurchfuehrenDialog;


public class DatumAuswaehlenDialogController {

    private final UeberweisungDurchfuehrenDialog parentDialog;

    private DatumAuswaehlenDialog dialog;


    public DatumAuswaehlenDialogController(UeberweisungDurchfuehrenDialog aParentDialog) {
        parentDialog = aParentDialog;
    }

    public void start() {
        dialog = new DatumAuswaehlenDialog(parentDialog, true);
        dialog.getBtOK().addActionListener(new OKAction());
        dialog.getBtAbbrechen().addActionListener(new AbbrechenAction());
    }


    // Inner Classes ***********************************************************

    private class OKAction extends AbstractAction {

        @Override
        protected void execute(ActionEvent aEvent) throws Exception {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
            parentDialog.getTfDatum().setText(dateFormat.format(dialog.getCalendar().getDate()));
            dialog.dispose();
        }
    }

    private class AbbrechenAction extends AbstractAction {

        @Override
        protected void execute(ActionEvent aEvent) throws Exception {
            dialog.dispose();
        }
    }
}
